package 斗地主_控制台版;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

public class PokerGame2 {
    //创建牌盒
    /*为牌发牌后,手中的牌自动排序,创建一个map集合,提前把每一张牌编上序号*/
    static HashMap<Integer,String> map=new HashMap<>();
    //创建存储牌的序号集合
   static  ArrayList<Integer> list=new ArrayList<>();
    static{
        //每一张牌的序号
        int Serialnumber=1;
        //创建数组用来存储花色和数字
        String[] color={"♥","♣","♦","♠"};
        String[] number={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        //遍历数组,不按照花色＋数字,按照数组+花色
        for (String s : number) {
            for (String s1 : color) {
                //添加牌
                map.put(Serialnumber,s+s1);
                list.add(Serialnumber);
                Serialnumber++;

            }
        }
        map.put(Serialnumber,"大王");
        list.add(Serialnumber);
        Serialnumber++;
        map.put(Serialnumber,"小王");
        list.add(Serialnumber);

    }
    public PokerGame2() {
        System.out.println(map);
        //发牌
        /*创建单列集合用来表示玩家和底牌,使用Treeset进行排序*/
        TreeSet<Integer> daPai1=new TreeSet<>();
        TreeSet<Integer> daPai2=new TreeSet<>();
        TreeSet<Integer> daPai3=new TreeSet<>();
        TreeSet<Integer> underCard=new TreeSet<>();
        //遍历序号集合,将对应的序号发个玩家
        Collections.shuffle(list);
        for (int i = 0; i < list.size(); i++) {

            Integer Serialnumber = list.get(i);
            //打乱排序

            if (i<3){
                underCard.add(Serialnumber);
                continue;
            }
            if (i%3==0){
                daPai1.add(Serialnumber);
            }else if (i%3==1){
                daPai2.add(Serialnumber);
            }else {
                daPai3.add(Serialnumber);
            }
        }

        addPoker("张三",daPai1);
        addPoker("李四",daPai2);
        addPoker("王五",daPai3);
        addPoker("地主牌",underCard);
    }

    /**
     * 打印map集合序号所对应的牌
     * @param name
     * 玩家姓名
     * @param set
     * 玩家序号集合
     */
    public static void addPoker(String name,TreeSet<Integer> set){
        System.out.print(name+":");
        for (int integer : set) {
            String s = map.get(integer);
            System.out.print(s+" ");
        }
        System.out.println("\n"+set.size()+"张牌");
    }
}
